package top.yzlin.jqueryjx3strategystation.dao;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import top.yzlin.jqueryjx3strategystation.entity.user.User;

import java.util.List;

@Repository
public interface UserDAO extends JpaRepository<User, Integer> {

    @Query("select count(u)>0 from User u where u.userName=:userName")
    boolean isExistUserByUserName(@Param("userName") String userName);


    @Query("from User u where u.userName=:userName and u.password=:password")
    User findUserByUserNameAndPassword(@Param("userName") String userName,@Param("password") String password);

    @Query("from User u where u.permissions='band'")
    List<User> findBanedUserList();


    @Query("update User u set u.permissions='band' where u.userId =:userId")
    int setUserEnband(@Param("userId")Integer userId);

    @Query("update User u set u.permissions='ordinary' where u.userId =:userId")
    int setUserDeband(@Param("userId")Integer userId);

    @Query("select u.permissions='band' from User u where u.userId=:userId")
    boolean isBanned(@Param("userId") int userId);
}
